'use strict'

// 不可行
// import Vue from './vue3.js'
// import ElementPlus from './element-plus.js'
// import ElementPlusIconsVue from './element-plus-icon.js'
// import ElementPlusLocaleZhCn from './locale/zh-cn.js'

import route from './route.js'
import Http from './http.js'

import MyMenu from '../templates/my-menu/my-menu.js'
import iconfont from '../templates/iconfont/iconfont.js'

window.onload = function () {
  /** 是否登录 */
  let token = localStorage.getItem('token')
  if (!token) {
    return
  } else {
    Http.headers['token'] = token
  }

  /** 创建app */
  const app = Vue.createApp({
    data() {
      return {
        currentComponent: 'null',
      }
    },
    provide() {
      return {
        RP,
      }
    },
  })
  /** 全集变量app */
  window.app = app
  window.app.route = route
  window.Http = Http
  Http.root = config.RP

  /**  */
  window.ElMessage = ElementPlus.ElMessage

  /** ElementPlus */
  app.use(ElementPlus, { locale: ElementPlusLocaleZhCn })
  /** Element icons */
  // for (const key in ElementPlusIconsVue) {
  //   if (Object.hasOwnProperty.call(ElementPlusIconsVue, key)) {
  //     app.component(key, ElementPlusIconsVue[key]);
  //   }
  // }
  let icons = ['Plus', 'Search', 'Refresh']
  for (const key of icons) {
    app.component(key, ElementPlusIconsVue[key])
  }

  /**　加载全局组件 */
  Promise.all([MyMenu.load(), iconfont.load()])
    .then(() => {
      app.mount('#app')
    })
    .catch((err) => {
      console.log(err)
    })
}
